package javashop;

import java.io.IOException;

import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

public class UserCreateServlet extends HttpServlet{
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException{
		UserService userService = UserServiceFactory.getUserService();
		User user = userService.getCurrentUser();
		ShopUserBean shopUser = new ShopUserBean(user, user.getNickname(), user.getEmail());
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try {
			ShopUserBean result = pm.makePersistent(shopUser);

		} finally {
			pm.close();
		}
		
		String url = "/templates/user_new.jsp";
		try {
			req.getRequestDispatcher(url).forward(req, resp);
		} catch (ServletException e) {
			e.printStackTrace();
		}
		
		
		return;
	}
}
